home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 088 / setupwc.arc / CDMON.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-12-01  |  7.1 KB  |  356 lines

  1. TITLE ** CXR DETECT MONITOR / RESET FOR FIDO **
  2. page 55,132
  3. name CDMON
  4.  
  5. ; *********************************************
  6. ;  CDMON - Carrier Detect (DCD) Monitoring
  7. ;          and Watchdog Program.
  8. ;
  9. ;  CDMON program for monitoring COM1 and COM2
  10. ;  Cxr Detect signals (IBM PC) and resetting
  11. ;  system to warm boot if carrier lost.
  12. ;
  13. ;  Author:  M. E. Zilmer / Soft Systems Assoc.
  14. ;  This program is licensed for public domain
  15. ;  use.  Commercial use is prohibited without
  16. ;  permission.  Direct inquiries to:
  17. ;
  18. ;  Matthew E. Zilmer
  19. ;  Soft Systems Associates
  20. ;  919 W. Baseline Rd.
  21. ;  Claremont, CA.  91711-1508
  22. ;
  23. ;  MASM 2.0 recommended as Macro-Assembler.
  24. ;
  25. ; -------------------------------------------------
  26. ; : 1.00  MEZ  Base Line Release (COM1, DCD=x20)  :
  27. ; : 1.10  MEZ  Update to command line args for    :
  28. ; :            COM port, DCD mask, drop timer.    :
  29. ; -------------------------------------------------
  30. ;
  31. ; ************************************************************************
  32. ;
  33. ; 1.1 - available on the cmd line in the following format ...
  34. ;
  35. ;  CDMON  C/[com]  M/[mask]  T/[ticks]
  36. ;
  37. ;  where      com =  1  or  2    to indicate COM1 or COM2
  38. ;                         <default = COM1>,
  39. ;
  40. ;             mask = xxx         your DCD mask value <default = 128>
  41. ;                 limit is 128,
  42. ;
  43. ;             ticks = yyy        timer ticks over which DCD can drop
  44. ;                 without warm start occurring
  45. ;                 <default = 27 or 1.5 Seconds>.
  46. ;                 limit is 255.
  47. ;
  48. ;  example:
  49. ;
  50. ;  CDMON  C/1 M/128  T/10     ; COM1, mask = 128.
  51. ;                 ; DCD drop time = 10 ticks (550 mS).
  52. ;
  53. ;  Not all options must be specified, however, any options used must
  54. ;  be in the order stated above.
  55. ;
  56. ; ***********************************************************************
  57.  
  58. MSR2        equ    2feH        ; modem status reg for COM2.
  59.  
  60. MSR1        equ    3feH        ; modem status reg for COM1.
  61.  
  62. DCDD        equ    128        ; Data CXR Detect mask bit.
  63.                     ; (128 for Hayes, USR Courier).
  64.  
  65. TIMEOUT        equ    275        ; default timeout millisecond count.
  66.  
  67. page
  68.  
  69. startup        segment    at    0ffffH
  70. restart        label    far        ; reboot location.
  71. startup        ends    
  72.  
  73. vectors        segment    at    0
  74.         org    1ch*4
  75. aux_vec        dw     2 dup (?)    ; aux timer vector.
  76. vectors     ends
  77.  
  78. data        segment    at    40h
  79.         org    72h
  80. reset_flag     db    ?        ; reboot flag.
  81. data        ends
  82.  
  83. page
  84.  
  85. code    segment    public    'code'
  86. assume    cs:code, ds:code, es:code, ss:nothing
  87.  
  88.     org    100H
  89.  
  90. start:
  91.     jmp    begin
  92.  
  93. no_dcd    db    0
  94. msr    dw    MSR1            ; default is COM1.
  95. dcd    db    DCDD            ; default mask bit.
  96. limit    db    TIMEOUT / 55        ; ticks for DCD drop reset.
  97. accum    dw    0            ; accum for get_dec_byte.
  98.  
  99. page
  100.  
  101. cxr_look proc    far            ; monitor DCD line.
  102.  
  103.     push    ds
  104.     push    dx
  105.     push    ax            ; save machine state.
  106.     mov    dx,cs
  107.     mov    ds,dx
  108.     mov    dx,msr            ; look at modem status register.
  109.     in    al,dx
  110.     and    al,dcd            ; test modem status for DCD. (act. DSR).
  111.  
  112.     jnz    cl_0
  113.     inc    no_dcd            ; increment carrier drop timer.
  114.     jmp    short cl_1        ; finish up - check drop count.
  115. cl_0:
  116.     mov    no_dcd,0
  117.     pop    ax
  118.     pop    dx
  119.     pop    ds
  120.     iret
  121. cl_1:
  122.     mov    al,limit
  123.     cmp    no_dcd,al        ; check drop count for X Ticks.
  124.     je    reset
  125.     pop    ax
  126.     pop    dx
  127.     pop    ds
  128.     iret                ; return control.
  129. reset:
  130.     mov    ax, data        ; set low RAM data segment.
  131.  
  132. assume ds:data
  133.  
  134.     mov    ds, ax
  135.     mov    bx, offset reset_flag
  136.     mov    word ptr [bx],1234H    ; set warm boot flag.
  137.     jmp    far ptr restart        ; restart.
  138.     
  139. cxr_look endp
  140.  
  141.     db    ' Soft Systems - CDMON v1.1',0  ; signature.
  142.  
  143. code_end    label    byte
  144.  
  145.     db    10h dup (0)
  146.  
  147.     page
  148.  
  149. ;    The code past 'code_end' is thrown away since it is never needed
  150. ;    again.
  151.  
  152. inimsg    db    '  CDMON v 1.1 - Carrier Drop Protect',0dh,0ah
  153.     db    '  Copyright (C)1985 Soft Systems Associates',0dh,0ah
  154.     db    '  Licensed for non-commercial and Public Domain use',0dh,0ah
  155.     db    '  and distribution.  COM'
  156. pmsg    db    '1 is being monitored',0dh,0ah,0ah,'$'
  157.  
  158. assume ds:code
  159.  
  160. begin    proc    near
  161.     mov    ax,cs
  162.     mov    ds,ax
  163.     mov    es,ax
  164.     push    ds
  165.  
  166. assume ds:vectors
  167.  
  168.     mov    ax,vectors
  169.     mov    ds,ax
  170.     mov    bx,offset aux_vec    ; intercept aux timer tick int.
  171.     mov    word ptr [bx],offset cxr_look
  172.     mov    [bx+2],cs        ; set vector to point at our code.
  173.     pop    ds
  174.  
  175. ; get command line args.  set msr, dcd and ticks accordingly.
  176.  
  177. assume ds:code
  178.  
  179.     mov    bx,80h            ; get char count after 'CDMON'.
  180.     mov    cl,[bx]
  181.     xor    ch,ch
  182.     inc    bx
  183.     call    nxnd            ; next non-delimiter.
  184.     jc    no_cla            ; no cmd line args found.
  185.  
  186. ; now see what that arg is ....
  187.  
  188.     mov    ax,[bx]            ; get that word.
  189.     or    al,20H            ; make lower.
  190.     cmp    ax,'/c'            ; COM port arg ?
  191.     jne    cla2a            ; check next.
  192.     inc    bx
  193.     inc    bx
  194.     cmp    byte ptr [bx],'1'    ; COM1?
  195.     jne    cla1
  196.     jmp    short cla2
  197. cla1:
  198.     cmp    byte ptr [bx],'2'    ; COM2?
  199.     jne    cla2
  200.     mov    msr,MSR2        ; set MSR port accordingly.
  201.     mov    pmsg,ah            ; put in monitoring msg.
  202. cla2:
  203.     mov    dx,offset inimsg    ; print banner.
  204.     mov    ah,9            ; print string fc.
  205.     int    21h
  206.  
  207.     call    nxd            ; get to next delimiter.
  208.     cmp    cx,0            ; see if out of chars.
  209.     je    no_cla
  210.     call    nxnd            ; next non-delim.
  211.     cmp    cx,0
  212.     je    no_cla            ; no change, mask is DCDD.
  213. cla2a:
  214.     mov    ax,[bx]
  215.     or    al,20H            ; make lower.
  216.     cmp    ax,'/m'            ; see if mask parm.
  217.     jne    cla3a            ; check Timer, now.
  218.     inc    bx            ; pass 'm/' up, get binary.
  219.     inc    bx
  220.     call    get_dec_byte        ; convert to binary.
  221.     mov    dcd,al            ; put in as mask.
  222.     call    nxd
  223.     jc    no_cla
  224.     call    nxnd
  225.     jc    no_cla
  226.     mov    ax,[bx]
  227.     or    al,20H
  228. cla3a:
  229.     cmp    ax,'/t'            ; see if ticks specified.
  230.     jne    no_cla
  231.     inc    bx
  232.     inc    bx
  233.     call    get_dec_byte
  234.     mov    limit,al
  235.  
  236. no_cla:
  237.     mov    dx,offset code_end+10h
  238.     int    27h            ; fully compatible KEEP call.
  239.                     ; terminate and stay resident.
  240.  
  241. ; that's all folks !!
  242.  
  243. begin    endp
  244. page
  245.  
  246. nxd    proc    near            ; find next [bx] delimiter.
  247.  
  248.     cmp    byte ptr [bx],' '    ; blank?
  249.     je    nxd1            ; found delim.
  250.     cmp    byte ptr [bx],','    ; comma.
  251.     je    nxd1
  252.     cmp    byte ptr [bx],0dh    ; cr or lf.
  253.     je    nxd1
  254.     cmp    byte ptr [bx],0ah
  255.     je    nxd1
  256.     dec    cx            ; decr count.
  257.     jnz    nxd0            ; next char.
  258.     stc                ; count exhausted.
  259.     ret
  260. nxd0:
  261.     inc    bx
  262.     jmp    nxd
  263. nxd1:
  264.     clc
  265.     ret
  266.  
  267. nxd    endp
  268.  
  269. nxnd    proc    near            ; find next [bx] non-delimiter.
  270.  
  271.  
  272.     cmp    byte ptr [bx],' '    ; blank?
  273.     je    nxnd0            ; found delim.
  274.     cmp    byte ptr [bx],','    ; comma.
  275.     je    nxnd0
  276.     cmp    byte ptr [bx],0dh    ; cr or lf.
  277.     je    nxnd0
  278.     cmp    byte ptr [bx],0ah
  279.     clc                ; found a delimiter.
  280.     ret
  281. nxnd0:
  282.     inc    bx
  283.     dec    cx
  284.     jnz    nxnd            ; count is exhausted.
  285.     stc
  286.     ret
  287.  
  288. nxnd    endp
  289. page
  290.  
  291. n100    dw    100
  292. n10    dw    10
  293.  
  294. get_dec_byte    proc    near        ; translate ascii decimal
  295.                     ;  at bx to binary byte in al.
  296.  
  297.     push    bx
  298.     mov    accum,0            ; zero accumulator.
  299.     push    bx
  300.     mov    si,bx
  301.     call    nxd            ; find end + 1.
  302.     pop    di
  303.     sub    bx,di            ; find length of decimal.
  304.     jne    gdb_nz
  305.     mov    al,0            ; zero length = 0.
  306.     pop    bx
  307.     ret
  308. gdb_nz:
  309.     dec    bx
  310.     je    gdb_2            ; length = 1, units only.
  311.     dec    bx
  312.     je    gdb_1            ; length = 2, tens, units.
  313.     dec    bx
  314.     je    gdb_0            ; length = 3, 100's, tens, units.
  315.     mov    al,0ffh            ; max byte length.
  316.     pop    bx
  317.     ret
  318. gdb_0:
  319.     mov    al,[si]            ; do 100's.
  320.     call    make_bin
  321.     xor    ah,ah
  322.     mul    cs:n100
  323.     add    accum,ax
  324.     inc    si
  325. gdb_1:
  326.     mov    al,[si]            ; do 10's.
  327.     call    make_bin
  328.     xor    ah,ah
  329.     mul    cs:n10
  330.     add    accum,ax
  331.     inc    si
  332. gdb_2:
  333.     mov    al,[si]            ; do 1's.
  334.     call    make_bin
  335.     xor    ah,ah
  336.     add    ax,accum
  337.     pop    bx
  338.     ret
  339.  
  340. get_dec_byte    endp
  341.  
  342. make_bin    proc    near        ; make binary from [bx] char.
  343.  
  344.     sub    al,'0'
  345.     cmp    al,9
  346.     ja    mb_0
  347.     ret
  348. mb_0:
  349.     sub    al,7
  350.     ret
  351.  
  352. make_bin    endp
  353.  
  354. code        ends
  355. end        start
  356.